package com.xwd.servlet;

import com.xwd.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName LoginOutServlet
 * @Description: com.xwd.servlet
 * @Auther: xiwd
 * @Date: 2022/2/12 - 02 - 12 - 21:11
 * @version: 1.0
 */
@WebServlet(
        name = "logincheckservlet",
        urlPatterns = {
                "/logincheckservlet.do"
        }
)
public class LoginCheckServlet extends HttpServlet {
    //methods
    //methods
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doGet(req, resp);
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doPost(req, resp);
        //判断是否登录
        HttpSession session = req.getSession();
        User user = (User)session.getAttribute("user");
        String msg="";
        if (null!=user){
            msg="已登录";
        }else {
            msg="未登录";
        }
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = resp.getWriter();
        writer.print(msg);
        writer.flush();
        writer.close();
    }
}
